home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / malloc.lha / malloc / mem-limits.h < prev    next >
C/C++ Source or Header  |  1993-05-31  |  3KB  |  133 lines

  1. /* Includes for memory limit warnings.
  2.    Copyright (C) 1990, 1993 Free Software Foundation, Inc.
  3.  
  4.  
  5. This file is part of the GNU C Library.
  6.  
  7. The GNU C Library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Library General Public License as
  9. published by the Free Software Foundation; either version 2 of the
  10. License, or (at your option) any later version.
  11.  
  12. The GNU C Library is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. Library General Public License for more details.
  16.  
  17. You should have received a copy of the GNU Library General Public
  18. License along with the GNU C Library; see the file COPYING.LIB.  If
  19. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  20. Cambridge, MA 02139, USA.  */
  21.  
  22. #if defined(__osf__) && (defined(__mips) || defined(mips))
  23. #include <sys/time.h>
  24. #include <sys/resource.h>
  25. #endif
  26.  
  27. #ifdef __bsdi__
  28. #define BSD4_2
  29. #endif
  30.  
  31. #ifndef BSD4_2
  32. #ifndef USG
  33. #include <sys/vlimit.h>
  34. #endif /* not USG */
  35. #else /* if BSD4_2 */
  36. #include <sys/time.h>
  37. #include <sys/resource.h>
  38. #endif /* BSD4_2 */
  39.  
  40. #ifdef emacs
  41. /* The important properties of this type are that 1) it's a pointer, and
  42.    2) arithmetic on it should work as if the size of the object pointed
  43.    to has a size of 1.  */
  44. #ifdef __STDC__
  45. typedef void *POINTER;
  46. #else
  47. typedef char *POINTER;
  48. #endif
  49.  
  50. typedef unsigned long SIZE;
  51.  
  52. #ifdef NULL
  53. #undef NULL
  54. #endif
  55. #define NULL ((POINTER) 0)
  56.  
  57. extern POINTER start_of_data ();
  58. #ifdef DATA_SEG_BITS
  59. #define EXCEEDS_LISP_PTR(ptr) \
  60.   (((unsigned int) (ptr) & ~DATA_SEG_BITS) >> VALBITS)
  61. #else
  62. #define EXCEEDS_LISP_PTR(ptr) ((unsigned int) (ptr) >> VALBITS)
  63. #endif
  64.  
  65. #ifdef BSD
  66. #ifndef DATA_SEG_BITS
  67. extern char etext;
  68. #define start_of_data() &etext
  69. #endif
  70. #endif
  71.  
  72. #else  /* Not emacs */ 
  73. extern char etext;
  74. #define start_of_data() &etext
  75. #endif /* Not emacs */
  76.  
  77.   
  78.  
  79. /* start of data space; can be changed by calling malloc_init */
  80. static POINTER data_space_start;
  81.  
  82. /* Number of bytes of writable memory we can expect to be able to get */
  83. static unsigned int lim_data;
  84.  
  85. #ifdef USG
  86.  
  87. static void
  88. get_lim_data ()
  89. {
  90.   extern long ulimit ();
  91.  
  92.   lim_data = -1;
  93.  
  94.   /* Use the ulimit call, if we seem to have it.  */
  95. #if !defined (ULIMIT_BREAK_VALUE) || defined (LINUX)
  96.   lim_data = ulimit (3, 0);
  97. #endif
  98.  
  99.   /* If that didn't work, just use the macro's value.  */
  100. #ifdef ULIMIT_BREAK_VALUE
  101.   if (lim_data == -1)
  102.     lim_data = ULIMIT_BREAK_VALUE;
  103. #endif
  104.  
  105.   lim_data -= (long) data_space_start;
  106. }
  107.  
  108. #else /* not USG */
  109. #if !defined(BSD4_2) && !defined(__osf__)
  110.  
  111. static void
  112. get_lim_data ()
  113. {
  114.   lim_data = vlimit (LIM_DATA, -1);
  115. }
  116.  
  117. #else /* BSD4_2 */
  118.  
  119. static void
  120. get_lim_data ()
  121. {
  122.   struct rlimit XXrlimit;
  123.  
  124.   getrlimit (RLIMIT_DATA, &XXrlimit);
  125. #ifdef RLIM_INFINITY
  126.   lim_data = XXrlimit.rlim_cur & RLIM_INFINITY; /* soft limit */
  127. #else
  128.   lim_data = XXrlimit.rlim_cur;    /* soft limit */
  129. #endif
  130. }
  131. #endif /* BSD4_2 */
  132. #endif /* not USG */
  133.